﻿using System;

namespace IupNET
{
    public class Toggle:Control
    {

        public Toggle()
            : base(Iupc.Toggle(null, null))
        {
            
        }

        

        public Alignment Alignment
        { //TODO: handle compined aligns (see iup manual)
            get
            {
                return Convert.StringToAlign(GetAttribute("ALIGNMENT"));
            }
            set
            {
                SetAttribute("ALIGNMENT", Convert.AlignToString(value));
            }
        }

        public bool CanFocus
        {
            get
            {
                return GetAttribute("CANFOCUS") == "YES";
            }
            set
            {
                SetAttribute("CANFOCUS", value ? "YES" : "NO");
            }
        }

        public Image Image
        {
            set
            {
                string n = value.HandleName;
                if (n == null)
                    return;
                SetAttribute("IMAGE", n);
            }
        }

        public Image ImInactive
        {
            set
            {
                string n = value.HandleName;
                if (n == null)
                    return;
                SetAttribute("IMINACTIVE", n);
            }
        }

        public Image ImPress
        {
            set
            {
                string n = value.HandleName;
                if (n == null)
                    return;
                SetAttribute("IMPRESS", n);
            }
        }

        public bool Markup
        {
            get
            {
                return GetAttribute("MARKUP") == "YES";
            }
            set
            {
                SetAttribute("MARKUP", value ? "YES" : "NO");
            }
        }

        public Size2i Padding
        {
            get
            {
                return Convert.StringToSize(GetAttribute("PADDING"));
            }
            set
            {
                SetAttribute("PADDING", Convert.SizeToString(value));
            }
        }

        public bool RightButton
        {
            get
            {
                return GetAttribute("RIGHTBUTTON") == "YES";
            }
            set
            {
                SetAttribute("RIGHTBUTTON", value ? "YES" : "NO");
            }
        }

        public bool Radio
        {
            get
            {
                return GetAttribute("RADIO") == "YES";
            }
            
        }

        public bool ThreeState
        {
            get
            {
                return GetAttribute("3STATE") == "YES";
            }
            set
            {
                SetAttribute("3STATE", value ? "YES" : "NO");
            }
        }

        

        public bool On
        {
            get
            {
                return GetAttribute("VALUE") == "ON";
            }
            set
            {
                if (value)
                    SetAttribute("VALUE", "ON");
                else
                    SetAttribute("VALUE", "OFF");
            }
        }

        public bool NoState
        {
            get
            {
                return GetAttribute("VALUE") == "NOTDEF";
            }
            set
            {
                if(value)
                    SetAttribute("VALUE", "NOTDEF");
                else
                    SetAttribute("VALUE", "OFF");

            }
        }

        public EventCallback Action
        {
            get
            {
                return CBHandler.Fetch("ACTION_TOGGLE");
            }
            set
            {
                CBHandler.Set("ACTION_TOGGLE", value);
            }
        }
    }
}
